package cn.seaboot.admin.goal;

import cn.seaboot.commons.core.CommonUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 目标树节点
 * <p>
 * 命名方式较为大众化，能直接对接各类组件
 *
 * @author Mr.css
 * @version 2024-04-26 10:50
 */
public class GoalNode<T> implements Serializable {
    private static final long serialVersionUID = -1224044714610140442L;
    /**
     * ID 关键字
     */
    private String id;
    /**
     * 父级 ID 关键字
     */
    private String pid;
    /**
     * 标签
     */
    private String label;
    /**
     * 图标
     */
    private String icon;
    /**
     * 逻辑关系
     */
    private Logical logical;
    /**
     * 目标树期望值
     */
    private int expected;
    /**
     * 目标树实际值
     */
    private int value;
    /**
     * 数据实体
     */
    private T data;
    /**
     * 父节点，这个字段不参与序列化
     */
    private transient GoalNode<T> parent;
    /**
     * 子节点
     */
    private List<GoalNode<T>> children;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public GoalNode<T> getParent() {
        return parent;
    }

    public void setParent(GoalNode<T> parent) {
        this.parent = parent;
    }

    public List<GoalNode<T>> getChildren() {
        return children;
    }

    public void setChildren(List<GoalNode<T>> children) {
        this.children = children;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public Logical getLogical() {
        return logical;
    }

    public void setLogical(Logical logical) {
        this.logical = logical;
    }

    public int getExpected() {
        return expected;
    }

    public void setExpected(int expected) {
        this.expected = expected;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    /**
     * 是否有父级
     *
     * @return if true
     */
    public boolean hasParent() {
        return this.parent != null;
    }

    /**
     * 是否有子节点
     *
     * @return if true
     */
    public boolean hasChildren() {
        return CommonUtils.isNotEmpty(children);
    }

    @Override
    public String toString() {
        return "GoalNode{" +
                "id='" + id + '\'' +
                ", pid='" + pid + '\'' +
                ", label='" + label + '\'' +
                ", icon='" + icon + '\'' +
                ", logical=" + logical +
                ", value=" + value +
                ", data=" + data +
                ", parent=" + parent +
                ", children=" + children +
                '}';
    }
}